package com.seven.good.service.impl;

import com.seven.good.dao.BidRecordMapper;
import com.seven.good.dto.BidRecordDTO;
import com.seven.good.exception.DaoException;
import com.seven.good.exception.ServiceException;
import com.seven.good.pojo.BidRecord;
import com.seven.good.service.BidRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <h3>easyauction</h3>
 *
 * @author : 王胜奔
 * @description : BidRecordService接口的实现类
 * @date : 2019-10-18 12:18
 **/
@Service
public class BidRecordServiceimpl implements BidRecordService {
    @Autowired
    private BidRecordMapper bidRecordMapper;
    //根据商品id查询出价次数
//    @Override
//    public int getBuyRecordByGid(Integer gid) {
//        return bidRecordMapper.selectBuyRecordByGid(gid);
//    }
    //倒序查询出价记录价格
//    @Override
//    public List<BidRecord> getBidRecoredsByGid(Integer gid) {
//        return bidRecordMapper.selectBidRecoredsByGid(gid);
//    }

    //用DTO封装了出价次数和倒序查询出价记录价格
   @Override
    public BidRecordDTO getBidRecored(Integer gid) {
        try {
            int bidNo=bidRecordMapper.selectBuyRecordByGid(gid);
            List<BidRecord>bidRecords= bidRecordMapper.selectBidRecoredsByGid(gid);
            BidRecordDTO bidRecordDTO = new BidRecordDTO();
            bidRecordDTO.setBidNo(bidNo);
            bidRecordDTO.setBidRecords(bidRecords);
            return bidRecordDTO;
        }catch (DaoException e){
            e.printStackTrace();
            throw new ServiceException("系统维护中");
        }
    }
    /**
    * @Description: 添加出价记录数据
    * @Param:  BidRecord对象
    * @return:
    * @Author: 王胜奔
     * exception:
    * @Date: 2019/10/19 15:03
    * Version: 1.0
    */
    @Override
    public void saveSelective(BidRecord bidRecord) {
        try {
            bidRecordMapper.insertSelective(bidRecord);
        }catch (DaoException e){
            e.printStackTrace();
            throw new ServiceException("系统维护中");
        }
    }

    /**
    * @Description: 根据商品id，出价时间，出价状态
    * @Param:  拍品id，当前时间
    * @return:  brid：出价记录表的主键
    * @Author: 王胜奔
     * exception:
    * @Date: 2019/10/19 15:00
    * Version: 1.0
    */
    @Override
    public int getOutBrid(Integer gid, Date currentTime) {
        try {
            int brid=bidRecordMapper.selectOutBrid(gid,currentTime);
            return brid;
        }catch (DaoException e){
            e.printStackTrace();
            throw new ServiceException("系统维护中");
        }

    }
    /**
    * @Description: 更改出局记录的状态
    * @Param:  出价记录表主键brid
    * @return:
    * @Author: 王胜奔
     * exception:
    * @Date: 2019/10/19 15:00
    * Version: 1.0
    */
    @Override
    public void modifyBidStateOutByBrid(Integer brid) {
        bidRecordMapper.updateBidStateOutByBrid(brid);

    }

    @Override
    public List<BidRecord> getBidRecoredsByGid(Integer currnetPage, Integer pageSize, Integer gid) {
        try {
            return bidRecordMapper.selectBidRecoredsByGid(currnetPage,pageSize,gid);
        }catch (DaoException e){
            e.printStackTrace();
            throw new ServiceException("系统维护中");
        }

    }


}
